import { LAYOUT, IFRAME_BLANK } from '/@/router/constant';
import { AppRouteModule } from '/@/router/types';
import { t } from '/@/hooks/web/useI18n';
import { Authority } from '/@/enums/authorityEnum';
import { usePermission } from '/@/hooks/web/usePermission';
import { openWindow } from '/@/utils';

const tb: AppRouteModule = {
  path: '/tb',
  name: 'Thingdboard',
  component: LAYOUT,
  redirect: () => {
    const { hasPermission } = usePermission();
    return {
      path: hasPermission(Authority.SYS_ADMIN) ? '/tenant/list' : '/device/list',
    };
  },
  meta: {
    icon: 'ant-design:windows-outlined',
    title: t('tb.deviceIn'),
    orderNo: 1,
  },
  children: [
    {
      path: '/home',
      name: 'TbHome',
      component: IFRAME_BLANK,
      meta: {
        icon: 'ant-design:home-outlined',
        tabIcon: 'ant-design:home-outlined',
        title: t('tb.home'),
        frameSrc: 'http://localhost:8080/home',
      },
      props: {
        offsetX: -254,
        offsetY: -70,
      },
    },
    {
      path: '/tenant-management',
      name: 'TenantManagement',
      component: LAYOUT,
      redirect: '/tenant/list',
      meta: {
        orderNo: 10,
        icon: 'ant-design:team-outlined',
        tabIcon: 'ant-design:team-outlined',
        title: t('tb.tenantManagement'),
        single: false,
        authority: [Authority.SYS_ADMIN],
      },
      children: [
        {
          path: '/tenant/list',
          name: 'TenantList',
          component: () => import('/@/views/tb/tenant/list.vue'),
          meta: {
            orderNo: 10,
            icon: 'ant-design:team-outlined',
            tabIcon: 'ant-design:team-outlined',
            title: t('tb.tenant'),
            authority: [Authority.SYS_ADMIN],
          },
        },
        {
          path: '/tenant/:tenantId/users',
          name: 'TenantAdminList',
          component: () => import('/@/views/tb/tenant/admin/list.vue'),
          meta: {
            orderNo: 15,
            icon: 'ant-design:user-outlined',
            tabIcon: 'ant-design:user-outlined',
            title: t('tb.tenantAdmin'),
            authority: [Authority.SYS_ADMIN],
          },
        },
        {
          path: '/tenant-profile/list',
          name: 'TenantProfileList',
          component: () => import('/@/views/tb/tenantProfile/list.vue'),
          meta: {
            orderNo: 20,
            icon: 'ant-design:project-outlined',
            tabIcon: 'ant-design:project-outlined',
            title: t('tb.tenantProfile'),
            authority: [Authority.SYS_ADMIN],
          },
        },
        {
          path: '/tenant-group/list',
          name: 'TenantGroupList',
          component: () => import('/@/views/tb/tenant-group/list.vue'),
          meta: {
            orderNo: 30,
            icon: 'ant-design:appstore-outlined',
            tabIcon: 'ant-design:appstore-outlined',
            title: t('tb.tenantGroup'),
            authority: [Authority.SYS_ADMIN],
          },
        },
      ],
    },
    {
      path: '/alarm/list',
      name: 'AlarmList',
      component: () => import('/@/views/tb/alarm/list.vue'),
      meta: {
        orderNo: 30,
        icon: 'ant-design:alert-outlined',
        tabIcon: 'ant-design:alert-outlined',
        title: t('tb.alarm'),
        authority: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
      },
    },
    {
      path: '/dashboard',
      name: 'Dashboard',
      component: LAYOUT,
      redirect: '/dashboard/list',
      meta: {
        orderNo: 35,
        icon: 'i-ant-design:layout-outlined',
        tabIcon: 'i-ant-design:layout-outlined',
        title: t('仪表板'),
        single: true,
        authority: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
      },
      children: [
        {
          path: '/dashboard/list',
          name: 'DashboardList',
          component: () => import('/@/views/tb/dashboard/list.vue'),
          meta: {
            icon: 'i-ant-design:layout-outlined',
            tabIcon: 'i-ant-design:layout-outlined',
            title: t('仪表板'),
            authority: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/dashboard/:dashboardId',
          name: 'DashboardEditor',
          component: () => import('/@/views/tb/dashboard/editor.vue'),
          meta: {
            icon: 'i-ant-design:layout-filled',
            tabIcon: 'i-ant-design:layout-filled',
            title: t('仪表板'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
      ],
    },
    {
      path: '/device',
      name: 'Device',
      component: LAYOUT,
      redirect: '/device/list',
      meta: {
        orderNo: 40,
        icon: 'ant-design:database-outlined',
        tabIcon: 'ant-design:team-outlined',
        title: t('设备管理'),
        single: false,
        authority: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
      },
      children: [
        {
          path: '/device/list',
          name: 'DeviceList',
          component: () => import('/@/views/tb/device/list.vue'),
          meta: {
            orderNo: 10,
            icon: 'ant-design:database-outlined',
            tabIcon: 'ant-design:database-outlined',
            title: t('tb.device'),
            authority: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/product/list',
          name: 'ProductList',
          component: () => import('/@/views/tb/product/list.vue'),
          meta: {
            icon: 'ant-design:project-outlined',
            tabIcon: 'ant-design:project-outlined',
            title: t('产品'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/group/list',
          name: 'GroupList',
          component: () => import('/@/views/tb/group/list.vue'),
          meta: {
            icon: 'ant-design:appstore-outlined',
            tabIcon: 'ant-design:appstore-outlined',
            title: t('分组'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
      ],
    },

    {
      path: '/asset/list',
      name: 'AssetList',
      component: () => import('/@/views/tb/asset/list.vue'),
      meta: {
        orderNo: 50,
        icon: 'ant-design:desktop-outlined',
        tabIcon: 'ant-design:desktop-outlined',
        title: t('tb.asset'),
        authority: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
      },
    },
    {
      path: '/entity-view/list',
      name: 'EntityViewList',
      component: () => import('/@/views/tb/entityView/list.vue'),
      meta: {
        orderNo: 60,
        icon: 'ant-design:windows-outlined',
        tabIcon: 'ant-design:windows-outlined',
        title: t('tb.entityView'),
        authority: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
      },
    },
    {
      path: '/ops-monitor',
      name: 'OpsMonitoring',
      component: LAYOUT,
      redirect: '/ops-monitor/release',
      meta: {
        orderNo: 70,
        icon: 'ant-design:monitor-outlined',
        tabIcon: 'ant-design:monitor-outlined',
        title: t('tb.opsMonitoring.menu'),
        single: false,
        authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
      },
      children: [
        {
          path: '/ops-monitor/service',
          name: 'OpsMonitoringService',
          component: IFRAME_BLANK,
          beforeEnter: () => {
            openWindow('https://148.70.47.141:30243/#/login', {
              target: '_self',
              noopener: false,
              noreferrer: false,
            });
            return false;
          },
          meta: {
            icon: 'ant-design:cluster-outlined',
            tabIcon: 'ant-design:cluster-outlined',
            title: t('tb.opsMonitoring.service'),
            href: 'https://148.70.47.141:30243/#/login',
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/ops-monitor/registry',
          name: 'OpsMonitoringRegistry',
          component: IFRAME_BLANK,
          beforeEnter: () => {
            openWindow('http://148.70.47.141', { target: '_self', noopener: false, noreferrer: false });
            return false;
          },
          meta: {
            icon: 'ant-design:database-filled',
            tabIcon: 'ant-design:database-filled',
            title: t('tb.opsMonitoring.registry'),
            href: 'http://148.70.47.141',
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/ops-monitor/release',
          name: 'OpsMonitoringRelease',
          component: IFRAME_BLANK,
          meta: {
            icon: 'ant-design:deployment-unit-outlined',
            tabIcon: 'ant-design:deployment-unit-outlined',
            title: t('tb.opsMonitoring.release'),
            frameSrc: 'http://148.70.47.141:31285/',
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/ops-monitor/system',
          name: 'OpsMonitoringSystem',
          component: IFRAME_BLANK,
          meta: {
            icon: 'ant-design:dashboard-outlined',
            tabIcon: 'ant-design:dashboard-outlined',
            title: t('tb.opsMonitoring.system'),
            frameSrc: 'http://148.70.47.141:30090/',
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/ops-monitor/data-board',
          name: 'OpsMonitoringDataBoard',
          component: IFRAME_BLANK,
          meta: {
            icon: 'ant-design:area-chart-outlined',
            tabIcon: 'ant-design:area-chart-outlined',
            title: t('tb.opsMonitoring.dataBoard'),
            frameSrc: 'https://148.70.47.141:31283',
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/ops-monitor/dashboard',
          name: 'OpsMonitoringDashboard',
          component: IFRAME_BLANK,
          meta: {
            icon: 'ant-design:bar-chart-outlined',
            tabIcon: 'ant-design:bar-chart-outlined',
            title: t('tb.opsMonitoring.dashboard'),
            frameSrc:
              'http://148.70.47.141:31283/d/dabdec12-750a-4e13-b4b1-f8cf245208a3/k8s-dashboard?orgId=1&from=1764054095205&to=1764055895205&theme=light&kiosk',
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/ops-monitor/alert',
          name: 'OpsMonitoringAlert',
          component: IFRAME_BLANK,
          meta: {
            icon: 'ant-design:alert-outlined',
            tabIcon: 'ant-design:alert-outlined',
            title: t('tb.opsMonitoring.alert'),
            frameSrc:
              'http://148.70.47.141:31283/alerting/list?orgId=1&from=1763538215365&to=1763540015366&theme=light&kiosk',
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
      ],
    },
    {
      path: 'profile',
      name: 'Profile',
      component: LAYOUT,
      redirect: '/profile/index',
      meta: {
        orderNo: 90,
        single: true,
        icon: 'ant-design:project-outlined',
        tabIcon: 'ant-design:project-outlined',
        title: t('tb.profile'),
        authority: [Authority.TENANT_ADMIN],
      },
      children: [
        {
          path: '/profile/index',
          name: 'ProfileIndex',
          component: () => import('/@/views/tb/profile/index.vue'),
          meta: {
            icon: 'ant-design:project-outlined',
            tabIcon: 'ant-design:project-outlined',
            title: t('tb.profile'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/asset-profile/list',
          name: 'AssetProfileList',
          component: () => import('/@/views/tb/assetProfile/list.vue'),
          meta: {
            icon: 'ant-design:profile-outlined',
            tabIcon: 'ant-design:profile-outlined',
            title: t('tb.assetProfile'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/device-profile/list',
          name: 'DeviceProfileList',
          component: () => import('/@/views/tb/deviceProfile/list.vue'),
          meta: {
            icon: 'ant-design:right-circle-outlined',
            tabIcon: 'ant-design:right-circle-outlined',
            title: t('tb.deviceProfile'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
      ],
    },
    {
      path: '/customer',
      name: 'Customer',
      component: LAYOUT,
      redirect: '/customer/users',
      meta: {
        orderNo: 100,
        icon: 'ant-design:team-outlined',
        tabIcon: 'ant-design:team-outlined',
        title: t('用户管理'),
        single: true,
        authority: [Authority.TENANT_ADMIN],
      },
      children: [
        {
          path: '/customer/users',
          name: 'CustomerUserList',
          component: () => import('/@/views/tb/customer/user/list.vue'),
          meta: {
            icon: 'ant-design:user-outlined',
            tabIcon: 'ant-design:user-outlined',
            title: t('用户管理'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
      ],
    },
    {
      path: '/role',
      name: 'Role',
      component: LAYOUT,
      redirect: '/role/list',
      meta: {
        orderNo: 110,
        icon: 'ant-design:safety-outlined',
        tabIcon: 'ant-design:safety-outlined',
        title: t('角色管理'),
        single: true,
        authority: [Authority.TENANT_ADMIN],
      },
      children: [
        {
          path: '/role/list',
          name: 'RoleList',
          component: () => import('/@/views/tb/role/list.vue'),
          meta: {
            icon: 'ant-design:safety-outlined',
            tabIcon: 'ant-design:safety-outlined',
            title: t('角色管理'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
      ],
    },
    {
      path: '/rule-chain',
      name: 'RuleChain',
      component: LAYOUT,
      redirect: '/rule-chain/list',
      meta: {
        orderNo: 120,
        icon: 'ant-design:subnode-outlined',
        tabIcon: 'ant-design:subnode-outlined',
        title: t('tb.ruleChain'),
        single: true,
        authority: [Authority.TENANT_ADMIN],
      },
      children: [
        {
          path: '/rule-chain/list',
          name: 'RuleChainList',
          component: () => import('/@/views/tb/ruleChain/list.vue'),
          meta: {
            icon: 'ant-design:subnode-outlined',
            tabIcon: 'ant-design:subnode-outlined',
            title: t('tb.ruleChain'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/rule-chain/:ruleChainId',
          name: 'RuleChainDetail',
          component: () => import('/@/views/tb/ruleChain/flow/index.vue'),
          meta: {
            single: true,
            icon: 'ant-design:subnode-outlined',
            tabIcon: 'ant-design:subnode-outlined',
            title: t('tb.ruleChainDetail'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
      ],
    },
    {
      path: '/otaPackage/list',
      name: 'OtaPackage',
      component: () => import('/@/views/tb/otaPackage/list.vue'),
      meta: {
        orderNo: 130,
        icon: 'ant-design:paper-clip-outlined',
        tabIcon: 'ant-design:paper-clip-outlined',
        title: t('tb.ota'),
        authority: [Authority.TENANT_ADMIN],
      },
    },
    {
      path: 'resources',
      name: 'Resource',
      component: LAYOUT,
      meta: {
        orderNo: 140,
        single: false,
        icon: 'ant-design:gold-outlined',
        tabIcon: 'ant-design:gold-outlined',
        title: t('tb.resource'),
        authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
      },
      children: [
        {
          path: '/widgets-bundle/list',
          name: 'widgetsBundleList',
          component: () => import('/@/views/tb/widgetsBundle/list.vue'),
          meta: {
            icon: 'i-ant-design:appstore-filled',
            tabIcon: 'i-ant-design:appstore-filled',
            title: t('tb.widgetsBundle'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/widget-type/list',
          name: 'widgetTypeList',
          component: () => import('/@/views/tb/widgetType/list.vue'),
          meta: {
            icon: 'i-ant-design:appstore-add-outlined',
            tabIcon: 'i-ant-design:appstore-add-outlined',
            title: t('tb.widgetType'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/image/list',
          name: 'imageList',
          component: () => import('/@/views/tb/images/list.vue'),
          meta: {
            icon: 'i-ant-design:file-image-outlined',
            tabIcon: 'i-ant-design:file-image-outlined',
            title: t('tb.images'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/scada-symbol/list',
          name: 'scadaSymbolList',
          component: () => import('/@/views/tb/scadaSymbol/list.vue'),
          meta: {
            icon: 'i-ant-design:codepen-outlined',
            tabIcon: 'i-ant-design:codepen-outlined',
            title: t('tb.scadaSymbols'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/scada-symbol/:type/:key',
          name: 'scadaSymbolDetail',
          component: () => import('/@/views/tb/scadaSymbol/detail.vue'),
          meta: {
            hideMenu: true,
            icon: 'i-ant-design:codepen-outlined',
            tabIcon: 'i-ant-design:codepen-outlined',
            title: t('tb.scadaSymbols'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/resource-library/list',
          name: 'ResourceLibraryList',
          component: () => import('/@/views/tb/resourceLibrary/list.vue'),
          meta: {
            icon: 'i-ant-design:build-outlined',
            tabIcon: 'i-ant-design:build-outlined',
            title: t('tb.resourceLibrary'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
      ],
    },
    {
      path: '/notification',
      name: 'Notification',
      component: LAYOUT,
      redirect: '/notification/index',
      meta: {
        orderNo: 160,
        single: true,
        icon: 'ant-design:comment-outlined',
        title: t('tb.notification_center'),
        authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
      },
      children: [
        {
          path: '/notification/index',
          name: 'NotificationIndex',
          component: () => import('/@/views/tb/notification/index.vue'),
          meta: {
            orderNo: 10,
            icon: 'ant-design:comment-outlined',
            title: t('tb.notification_center'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/notification/list',
          name: 'NotificationList',
          component: () => import('/@/views/tb/notification/list.vue'),
          meta: {
            orderNo: 20,
            icon: 'ant-design:bell-outlined',
            title: t('tb.notification_list'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
          },
        },
        {
          path: '/notification/request/list',
          name: 'NotificationRequestList',
          component: () => import('/@/views/tb/notification/request/list.vue'),
          meta: {
            orderNo: 30,
            icon: 'ant-design:bars-outlined',
            title: t('tb.notification_request_list'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/notification/recipient/list',
          name: 'NotificationRecipientList',
          component: () => import('/@/views/tb/notification/recipient/list.vue'),
          meta: {
            orderNo: 40,
            icon: 'ant-design:team-outlined',
            title: t('tb.notification_recipient_list'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/notification/template/list',
          name: 'NotificationTemplateList',
          component: () => import('/@/views/tb/notification/template/list.vue'),
          meta: {
            orderNo: 50,
            icon: 'ant-design:solution-outlined',
            title: t('tb.notification_template_list'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/notification/rule/list',
          name: 'NotificationRuleList',
          component: () => import('/@/views/tb/notification/rule/list.vue'),
          meta: {
            orderNo: 60,
            icon: 'ant-design:ungroup-outlined',
            title: t('tb.notification_rule_list'),
            authority: [Authority.SYS_ADMIN, Authority.TENANT_ADMIN],
          },
        },
      ],
    },
    {
      path: 'admin-setting',
      name: 'AdminSetting',
      component: LAYOUT,
      meta: {
        orderNo: 170,
        single: true,
        icon: 'ant-design:setting-outlined',
        tabIcon: 'ant-design:setting-outlined',
        title: t('tb.adminSetting'),
        authority: [Authority.SYS_ADMIN],
      },
      children: [
        {
          path: '/admin-setting/index',
          name: 'AdminSettingIndex',
          component: () => import('/@/views/tb/setting/index.vue'),
          meta: {
            icon: 'ant-design:setting-outlined',
            tabIcon: 'ant-design:setting-outlined',
            title: t('tb.adminSetting'),
            authority: [Authority.SYS_ADMIN],
          },
        },
      ],
    },
    {
      path: '/audit-log',
      name: 'AuditLog',
      component: () => import('/@/views/tb/auditLog/list.vue'),
      meta: {
        orderNo: 200,
        icon: 'ant-design:bars-outlined',
        tabIcon: 'ant-design:bars-outlined',
        title: t('tb.auditLog'),
        authority: [Authority.TENANT_ADMIN],
      },
    },
    {
      path: '/log-management',
      name: 'LogManagement',
      component: LAYOUT,
      redirect: '/log-management/terminal',
      meta: {
        orderNo: 210,
        icon: 'ant-design:file-text-outlined',
        tabIcon: 'ant-design:file-text-outlined',
        title: t('日志管理'),
        single: false,
        authority: [Authority.TENANT_ADMIN],
      },
      children: [
        {
          path: '/log-management/terminal',
          name: 'TerminalLogList',
          component: () => import('/@/views/tb/terminal-log/list.vue'),
          meta: {
            icon: 'ant-design:mobile-outlined',
            tabIcon: 'ant-design:mobile-outlined',
            title: t('终端日志'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
        {
          path: '/log-management/platform',
          name: 'PlatformLogList',
          component: () => import('/@/views/tb/platform-log/list.vue'),
          meta: {
            icon: 'ant-design:cloud-server-outlined',
            tabIcon: 'ant-design:cloud-server-outlined',
            title: t('平台日志'),
            authority: [Authority.TENANT_ADMIN],
          },
        },
      ],
    },
  ],
};

export default tb;
